-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Migrate file I/O tasks to multithreadable task API #12914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate file I/O tasks to multithreadable task API #12914
Conversation
…n status Co-authored-by: JanProvaznik <[email protected]>
…s section Co-authored-by: JanProvaznik <[email protected]>
- Updated FileState.cs to accept TaskEnvironment parameter - Migrated 7 File I/O tasks to IMultiThreadableTask: * Copy - added attribute, interface, TaskEnvironment property and updated path/environment access * Delete - migrated with proper path resolution * MakeDir - migrated with path deduplication * RemoveDir - migrated with directory operations * Touch - migrated with file timestamp operations * ReadLinesFromFile - migrated for file reading * WriteLinesToFile - migrated for file writing - All tasks use MSBuildMultiThreadableTaskAttribute for routing - All tasks implement IMultiThreadableTask for TaskEnvironment access - Tasks use TaskEnvironment.GetAbsolutePath() for thread-safe path resolution - Tasks use TaskEnvironment.GetEnvironmentVariable() for thread-safe environment access Co-authored-by: JanProvaznik <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR converts several file I/O tasks to support multi-threaded execution by implementing IMultiThreadableTask and using TaskEnvironment for thread-safe path resolution. The changes replace static path resolution methods with instance-based TaskEnvironment.GetAbsolutePath() calls to ensure proper path handling in concurrent scenarios.
Key Changes:
- Added
IMultiThreadableTaskinterface and[MSBuildMultiThreadableTask]attribute to 7 file I/O task classes - Introduced
TaskEnvironmentproperty to all modified tasks for thread-safe operations - Modified
FileStateconstructor to requireTaskEnvironmentparameter and use it for path resolution
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tasks/Touch.cs | Added multithreading support; uses TaskEnvironment for path resolution in TouchFile method |
| src/Tasks/RemoveDir.cs | Added multithreading support; resolves paths using TaskEnvironment in Execute and RemoveDirectory methods |
| src/Tasks/MakeDir.cs | Added multithreading support; uses TaskEnvironment for path resolution and deduplication |
| src/Tasks/FileState.cs | Modified constructor to require TaskEnvironment parameter; uses it for absolute path resolution in Lazy initialization |
| src/Tasks/FileIO/WriteLinesToFile.cs | Added multithreading support; uses TaskEnvironment for path resolution instead of FileUtilities.NormalizePath |
| src/Tasks/FileIO/ReadLinesFromFile.cs | Added multithreading support; resolves file paths using TaskEnvironment before file operations |
| src/Tasks/Delete.cs | Added multithreading support; uses TaskEnvironment for path resolution in delete operations |
| src/Tasks/Copy.cs | Added multithreading support; uses TaskEnvironment for path resolution, environment variables, and FileState construction; changed PathsAreIdentical from static to instance method |
AR-May
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I would like one more review to ensure there is no behavior change in multi process mode.
Co-authored-by: AR-May <[email protected]>
…://github.com/JanProvaznik/msbuild into copilot/outline-threading-fixes-logic-updates
### Context PRs #12914 and #12868 showed that we need to be able to fix and normalize `AbsolutePath`. Corresponding methods for strings live in `FileUtilities.cs` that is a Shared file and cannot reference Framework classes like `AbsolutePath`. ### Changes Made - Moved some related functions to FrameworkFileUtilities class. - Added the needed functions for `AbsolutePath` ### Testing unit tests
…#13079) ### Context PRs dotnet#12914 and dotnet#12868 showed that we need to be able to fix and normalize `AbsolutePath`. Corresponding methods for strings live in `FileUtilities.cs` that is a Shared file and cannot reference Framework classes like `AbsolutePath`. ### Changes Made - Moved some related functions to FrameworkFileUtilities class. - Added the needed functions for `AbsolutePath` ### Testing unit tests
|
[celebrate] Yuliia Kovalova reacted to your message:
…________________________________
From: Jan Provazník ***@***.***>
Sent: Monday, January 26, 2026 9:36:11 AM
To: dotnet/msbuild ***@***.***>
Cc: Yuliia Kovalova ***@***.***>; Review requested ***@***.***>
Subject: Re: [dotnet/msbuild] Migrate file I/O tasks to multithreadable task API (PR #12914)
Merged #12914<#12914> into main.
—
Reply to this email directly, view it on GitHub<#12914 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AWYM53WTVD6AU4AVU3GUXOL4IXNYXAVCNFSM6AAAAACOUJ74G2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMRSGI4DINZZGM3TOMQ>.
You are receiving this because your review was requested.Message ID: ***@***.***>
|
fixes #12484
This PR migrates several file I/O tasks to use the new multithreadable task API by implementing the \IMultiThreadableTask\ interface and using \TaskEnvironment\ for thread-safe path resolution. The aim is to be maximally compatible with prior behavior in terms of where it would throw
Changes
The following tasks now implement \IMultiThreadableTask\ and use \TaskEnvironment.GetAbsolutePath()\ instead of \Path.GetFullPath():
Why
\Path.GetFullPath()\ uses process-global state (current working directory) which is not thread-safe when multiple tasks run in parallel. The \TaskEnvironment.GetAbsolutePath()\ method provides thread-safe path resolution by using the task's execution context.
This enables these tasks to be safely executed in parallel when MSBuild's multithreading is enabled.